Skip to content

Commit 09d0a8e

Browse files
committed
io_uring: move max entry definition and ring sizing into header
In preparation for needing this somewhere else, move the definitions for the maximum CQ and SQ ring size into io_uring.h. Make the rings_size() helper available as well, and have it take just the setup flags argument rather than the fill ring pointer. That's all that is needed. Signed-off-by: Jens Axboe <[email protected]>
1 parent 882dec6 commit 09d0a8e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

io_uring/io_uring.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@
105105
#include "alloc_cache.h"
106106
#include "eventfd.h"
107107

108-
#define IORING_MAX_ENTRIES 32768
109-
#define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES)
110-
111108
#define SQE_COMMON_FLAGS (IOSQE_FIXED_FILE | IOSQE_IO_LINK | \
112109
IOSQE_IO_HARDLINK | IOSQE_ASYNC)
113110

@@ -2667,16 +2664,16 @@ static void io_rings_free(struct io_ring_ctx *ctx)
26672664
ctx->sq_sqes = NULL;
26682665
}
26692666

2670-
static unsigned long rings_size(struct io_ring_ctx *ctx, unsigned int sq_entries,
2671-
unsigned int cq_entries, size_t *sq_offset)
2667+
unsigned long rings_size(unsigned int flags, unsigned int sq_entries,
2668+
unsigned int cq_entries, size_t *sq_offset)
26722669
{
26732670
struct io_rings *rings;
26742671
size_t off, sq_array_size;
26752672

26762673
off = struct_size(rings, cqes, cq_entries);
26772674
if (off == SIZE_MAX)
26782675
return SIZE_MAX;
2679-
if (ctx->flags & IORING_SETUP_CQE32) {
2676+
if (flags & IORING_SETUP_CQE32) {
26802677
if (check_shl_overflow(off, 1, &off))
26812678
return SIZE_MAX;
26822679
}
@@ -2687,7 +2684,7 @@ static unsigned long rings_size(struct io_ring_ctx *ctx, unsigned int sq_entries
26872684
return SIZE_MAX;
26882685
#endif
26892686

2690-
if (ctx->flags & IORING_SETUP_NO_SQARRAY) {
2687+
if (flags & IORING_SETUP_NO_SQARRAY) {
26912688
*sq_offset = SIZE_MAX;
26922689
return off;
26932690
}
@@ -3434,7 +3431,8 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
34343431
ctx->sq_entries = p->sq_entries;
34353432
ctx->cq_entries = p->cq_entries;
34363433

3437-
size = rings_size(ctx, p->sq_entries, p->cq_entries, &sq_array_offset);
3434+
size = rings_size(ctx->flags, p->sq_entries, p->cq_entries,
3435+
&sq_array_offset);
34383436
if (size == SIZE_MAX)
34393437
return -EOVERFLOW;
34403438

io_uring/io_uring.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ static inline bool io_should_wake(struct io_wait_queue *iowq)
6565
return dist >= 0 || atomic_read(&ctx->cq_timeouts) != iowq->nr_timeouts;
6666
}
6767

68+
#define IORING_MAX_ENTRIES 32768
69+
#define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES)
70+
71+
unsigned long rings_size(unsigned int flags, unsigned int sq_entries,
72+
unsigned int cq_entries, size_t *sq_offset);
6873
bool io_cqe_cache_refill(struct io_ring_ctx *ctx, bool overflow);
6974
int io_run_task_work_sig(struct io_ring_ctx *ctx);
7075
void io_req_defer_failed(struct io_kiocb *req, s32 res);

0 commit comments

Comments
 (0)