Skip to content

Commit 5611257

Browse files
isilenceaxboe
authored andcommitted
io_uring: delay sqarray static branch disablement
io_key_has_sqarray static branch can be easily switched on/off by the user every time patching the kernel. That can be very disruptive as it might require heavy synchronisation across all CPUs. Use deferred static keys, which can rate-limit it by deferring, batching and potentially effectively eliminating dec+inc pairs. Fixes: 9b296c6 ("io_uring: static_key for !IORING_SETUP_NO_SQARRAY") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6b34f8e commit 5611257

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

io_uring/io_uring.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
static void io_queue_sqe(struct io_kiocb *req, unsigned int extra_flags);
120120
static void __io_req_caches_free(struct io_ring_ctx *ctx);
121121

122-
static __read_mostly DEFINE_STATIC_KEY_FALSE(io_key_has_sqarray);
122+
static __read_mostly DEFINE_STATIC_KEY_DEFERRED_FALSE(io_key_has_sqarray, HZ);
123123

124124
struct kmem_cache *req_cachep;
125125
static struct workqueue_struct *iou_wq __ro_after_init;
@@ -1978,7 +1978,7 @@ static bool io_get_sqe(struct io_ring_ctx *ctx, const struct io_uring_sqe **sqe)
19781978
unsigned mask = ctx->sq_entries - 1;
19791979
unsigned head = ctx->cached_sq_head++ & mask;
19801980

1981-
if (static_branch_unlikely(&io_key_has_sqarray) &&
1981+
if (static_branch_unlikely(&io_key_has_sqarray.key) &&
19821982
(!(ctx->flags & IORING_SETUP_NO_SQARRAY))) {
19831983
head = READ_ONCE(ctx->sq_array[head]);
19841984
if (unlikely(head >= ctx->sq_entries)) {
@@ -2173,7 +2173,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
21732173
io_rings_free(ctx);
21742174

21752175
if (!(ctx->flags & IORING_SETUP_NO_SQARRAY))
2176-
static_branch_dec(&io_key_has_sqarray);
2176+
static_branch_slow_dec_deferred(&io_key_has_sqarray);
21772177

21782178
percpu_ref_exit(&ctx->refs);
21792179
free_uid(ctx->user);
@@ -2946,7 +2946,7 @@ static __cold int io_uring_create(struct io_ctx_config *config)
29462946
ctx->clock_offset = 0;
29472947

29482948
if (!(ctx->flags & IORING_SETUP_NO_SQARRAY))
2949-
static_branch_inc(&io_key_has_sqarray);
2949+
static_branch_deferred_inc(&io_key_has_sqarray);
29502950

29512951
if ((ctx->flags & IORING_SETUP_DEFER_TASKRUN) &&
29522952
!(ctx->flags & IORING_SETUP_IOPOLL))

0 commit comments

Comments
 (0)