diff mbox series

[liburing,1/2] setup: add IORING_SETUP_NO_SQARRAY support

Message ID 2badb194856fad38ef1a9049e4cf121a9516b7f9.1695988793.git.asml.silence@gmail.com (mailing list archive)
State New
Headers show
Series liburing IORING_SETUP_NO_SQARRAY support | expand

Commit Message

Pavel Begunkov Sept. 29, 2023, 12:09 p.m. UTC
IORING_SETUP_NO_SQARRAY removes sq_array from the kernel, and hence when
set liburing should not try to mmap and initialise it.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 src/include/liburing/io_uring.h |  5 +++++
 src/setup.c                     | 14 +++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index 10a6ef0..793d64f 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -185,6 +185,11 @@  enum {
  */
 #define IORING_SETUP_REGISTERED_FD_ONLY	(1U << 15)
 
+/*
+ * Removes indirection through the SQ index array.
+ */
+#define IORING_SETUP_NO_SQARRAY		(1U << 16)
+
 enum io_uring_op {
 	IORING_OP_NOP,
 	IORING_OP_READV,
diff --git a/src/setup.c b/src/setup.c
index 2dcb5aa..a0e8296 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -76,7 +76,8 @@  static void io_uring_setup_ring_pointers(struct io_uring_params *p,
 	sq->kring_entries = sq->ring_ptr + p->sq_off.ring_entries;
 	sq->kflags = sq->ring_ptr + p->sq_off.flags;
 	sq->kdropped = sq->ring_ptr + p->sq_off.dropped;
-	sq->array = sq->ring_ptr + p->sq_off.array;
+	if (!(p->flags & IORING_SETUP_NO_SQARRAY))
+		sq->array = sq->ring_ptr + p->sq_off.array;
 
 	cq->khead = cq->ring_ptr + p->cq_off.head;
 	cq->ktail = cq->ring_ptr + p->cq_off.tail;
@@ -220,7 +221,8 @@  static int io_uring_alloc_huge(unsigned entries, struct io_uring_params *p,
 	ring_mem = cq_entries * sizeof(struct io_uring_cqe);
 	if (p->flags & IORING_SETUP_CQE32)
 		ring_mem *= 2;
-	ring_mem += sq_entries * sizeof(unsigned);
+	if (!(p->flags & IORING_SETUP_NO_SQARRAY))
+		ring_mem += sq_entries * sizeof(unsigned);
 	mem_used = sqes_mem + ring_mem;
 	mem_used = (mem_used + page_size - 1) & ~(page_size - 1);
 
@@ -335,11 +337,13 @@  static int __io_uring_queue_init_params(unsigned entries, struct io_uring *ring,
 	/*
 	 * Directly map SQ slots to SQEs
 	 */
-	sq_array = ring->sq.array;
 	sq_entries = ring->sq.ring_entries;
-	for (index = 0; index < sq_entries; index++)
-		sq_array[index] = index;
 
+	if (!(p->flags & IORING_SETUP_NO_SQARRAY)) {
+		sq_array = ring->sq.array;
+		for (index = 0; index < sq_entries; index++)
+			sq_array[index] = index;
+	}
 	ring->features = p->features;
 	ring->flags = p->flags;
 	ring->enter_ring_fd = fd;